<?php
class content_form {
	public $modelid;
	public $fields;
	public $id;
	public $formValidator;
	public function __construct($modelid, $catid = 0, $categorys = array()) {
		$this->modelid = $modelid;
		$this->catid = $catid;
		$this->categorys = $categorys;
		$this->fields = S ( 'model/model_field_' . $modelid );
	}
	public function get($data = array()) {
		$_groupid = cookie ( '_groupid' );
		$this->data = $data;
		if (isset ( $data ['id'] )) $this->id = $data ['id'];
		$info = array ();
		$this->content_url = isset ( $data ['url'] ) ? $data ['url'] : '';
		foreach ( $this->fields as $field => $v ) {
			if (defined ( 'IN_ADMIN' )) {
				if ($v ['iscore'] || check_in ( $_SESSION ['roleid'], $v ['unsetroleids'] )) continue;
			} else {
				if ($v ['iscore'] || ! $v ['isadd'] || check_in ( $_groupid, $v ['unsetgroupids'] )) continue;
			}
			$func = $v ['formtype'];
			$value = isset ( $data [$field] ) ? htmlspecialchars ( $data [$field], ENT_QUOTES ) : '';
			if ($func == 'pages' && isset ( $data ['maxcharperpage'] )) {
				$value = $data ['paginationtype'] . '|' . $data ['maxcharperpage'];
			}
			if (! method_exists ( $this, $func )) continue;
			$form = $this->$func ( $field, $value, $v );
			if ($form !== false) {
				if (defined ( 'IN_ADMIN' )) {
					if ($v ['isbase']) {
						$star = $v ['minlength'] || $v ['pattern'] ? 1 : 0;
						$info ['base'] [$field] = array ('name' => $v ['name'],'tips' => $v ['tips'],'form' => $form,'star' => $star,'isomnipotent' => $v ['isomnipotent'],'formtype' => $v ['formtype'] );
					} else {
						$star = $v ['minlength'] || $v ['pattern'] ? 1 : 0;
						$info ['senior'] [$field] = array ('name' => $v ['name'],'tips' => $v ['tips'],'form' => $form,'star' => $star,'isomnipotent' => $v ['isomnipotent'],'formtype' => $v ['formtype'] );
					}
				} else {
					$star = $v ['minlength'] || $v ['pattern'] ? 1 : 0;
					$info [$field] = array ('name' => $v ['name'],'tips' => $v ['tips'],'form' => $form,'star' => $star,'isomnipotent' => $v ['isomnipotent'],'formtype' => $v ['formtype'] );
				}
			}
		}
		return $info;
	}
	public function author($field, $value, $fieldinfo) {
		return '<input type="text" name="info[' . $field . ']" value="' . $value . '" size="30">';
	}
	public function box($field, $value, $fieldinfo) {
		$setting = string2array ( $fieldinfo ['setting'] );
		if ($value == '') $value = $this->fields [$field] ['defaultvalue'];
		$options = explode ( "\n", $this->fields [$field] ['options'] );
		foreach ( $options as $_k ) {
			$v = explode ( "|", $_k );
			$k = trim ( $v [1] );
			$option [$k] = $v [0];
		}
		$values = explode ( ',', $value );
		$value = array ();
		foreach ( $values as $_k ) {
			if ($_k != '') $value [] = $_k;
		}
		$value = implode ( ',', $value );
		switch ($this->fields [$field] ['boxtype']) {
			case 'radio' :
				$string = Form::radio ( $option, $value, "name='info[$field]' $fieldinfo[formattribute]", $setting ['width'], $field );
				break;
			case 'checkbox' :
				$string = Form::checkbox ( $option, $value, "name='info[$field][]' $fieldinfo[formattribute]", 1, $setting ['width'], $field );
				break;
			case 'select' :
				$string = Form::select ( $option, $value, "name='info[$field]' id='$field' $fieldinfo[formattribute]" );
				break;
			case 'multiple' :
				$string = Form::select ( $option, $value, "name='info[$field][]' id='$field ' size=2 multiple='multiple' style='height:60px;' $fieldinfo[formattribute]" );
				break;
		}
		return $string;
	}
	public function catid($field, $value, $fieldinfo) {
		if (! $value) $value = $this->catid;
		$publish_str = '';
		if (defined ( 'IN_ADMIN' ) && ACTION == 'add') $publish_str = " <a href='javascript:;' onclick=\"omnipotent('selectid','?app=content&controller=content&action=add_othors','" . L ( 'publish_to_othor_category' ) . "',1);return false;\" style='color:#B5BFBB'>[" . L ( 'publish_to_othor_category' ) . "]</a><ul class='list-dot-othors' id='add_othors_text'></ul>";
		return '<input type="hidden" name="info[' . $field . ']" value="' . $value . '">' . $this->categorys [$value] ['catname'] . $publish_str;
	}
	function copyfrom($field, $value, $fieldinfo) {
		$value_data = '';
		if ($value && strpos ( $value, '|' ) !== false) {
			$arr = explode ( '|', $value );
			$value = $arr [0];
			$value_data = $arr [1];
		}
		$copyfrom_array = S ( 'admin/copyfrom' );
		$copyfrom_datas = array (L ( 'copyfrom_tips' ) );
		if (! empty ( $copyfrom_array )) {
			foreach ( $copyfrom_array as $_k => $_v ) {
				$copyfrom_datas [$_k] = $_v ['sitename'];
			}
		}
		return "<input type='text' name='info[$field]' value='$value' style='width: 400px;' class='input-text'>" . Form::select ( $copyfrom_datas, $value_data, "name='{$field}_data' " );
	}
	public function datetime($field, $value, $fieldinfo) {
		extract ( string2array ( $fieldinfo ['setting'] ) );
		$isdatetime = 0;
		$timesystem = 0;
		if ($fieldtype == 'int') {
			if (! $value) $value = TIME;
			$format_txt = $format == 'm-d' ? 'm-d' : $format;
			if ($format == 'Y-m-d Ah:i:s') $format_txt = 'Y-m-d h:i:s';
			$value = date ( $format_txt, $value );
			$isdatetime = strlen ( $format ) > 6 ? 1 : 0;
			if ($format == 'Y-m-d Ah:i:s') {
				$timesystem = 0;
			} else {
				$timesystem = 1;
			}
		} elseif ($fieldtype == 'datetime') {
			$isdatetime = 1;
			$timesystem = 1;
		} elseif ($fieldtype == 'datetime_a') {
			$isdatetime = 1;
			$timesystem = 0;
		}
		return Form::date ( "info[$field]", $value, $isdatetime, 1, 'true', $timesystem );
	}
	public function downfile($field, $value, $fieldinfo) {
		$list_str = $str = '';
		extract ( string2array ( $fieldinfo ['setting'] ) );
		if ($value) {
			$value_arr = explode ( '|', $value );
			$value = $value_arr ['0'];
			$sel_server = $value_arr ['1'] ? explode ( ',', $value_arr ['1'] ) : '';
			$edit = 1;
		} else {
			$edit = 0;
		}
		$server_list = S ( 'common/downserver' );
		if (is_array ( $server_list )) {
			foreach ( $server_list as $_k => $_v ) {
				$checked = $edit ? ((is_array ( $sel_server ) && in_array ( $_k, $sel_server )) ? ' checked' : '') : ' checked';
				$list_str .= "<lable id='downfile{$_k}' class='ib lh24' style='width:25%'><input type='checkbox' value='{$_k}' name='{$field}_servers[]' {$checked}>  {$_v['sitename']}</lable>";
			}
		}

		$string = '
	<fieldset class="blue pad-10">
	<legend>' . L ( 'mirror_server_list' ) . '</legend>';
		$string .= $list_str;
		$string .= '</fieldset>
	<div class="bk10"></div>
	';
		if (! defined ( 'IMAGES_INIT' )) {
			$str = '<script type="text/javascript" src="' . JS_PATH . 'swfupload/swf2ckeditor.js"></script>';
			define ( 'IMAGES_INIT', 1 );
		}
		$authkey = upload_key ( "$upload_number,$upload_allowext,$isselectimage" );
		$string .= $str . "<input type='text' name='info[$field]' id='$field' value='$value' class='input-text' style='width:80%'/>  <input type='button' class='button' onclick=\"javascript:flashupload('{$field}_downfield', '" . L ( 'attachment_upload' ) . "','{$field}',submit_files,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/ value='" . L ( 'upload_soft' ) . "'>";
		return $string;
	}
	function downfiles($field, $value, $fieldinfo) {
		extract ( string2array ( $fieldinfo ['setting'] ) );
		$list_str = '';
		if ($value) {
			$value = string2array ( html_entity_decode ( $value, ENT_QUOTES ) );
			if (is_array ( $value )) {
				foreach ( $value as $_k => $_v ) {
					$list_str .= "<div id='multifile{$_k}'><input type='text' name='{$field}_fileurl[]' value='{$_v[fileurl]}' style='width:310px;' class='input-text'> <input type='text' name='{$field}_filename[]' value='{$_v[filename]}' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('multifile{$_k}')\">" . L ( 'remove_out' ) . "</a></div>";
				}
			}
		}
		$string = '<input name="info[' . $field . ']" type="hidden" value="1">
	<fieldset class="blue pad-10">
	<legend>' . L ( 'file_list' ) . '</legend>';
		$string .= $list_str;
		$string .= '<ul id="' . $field . '" class="picList"></ul>
	</fieldset>
	<div class="bk10"></div>
	';

		if (! defined ( 'IMAGES_INIT' )) {
			$str = '<script type="text/javascript" src="' . JS_PATH . 'swfupload/swf2ckeditor.js"></script>';
			define ( 'IMAGES_INIT', 1 );
		}
		$authkey = upload_key ( "$upload_number,$upload_allowext,$isselectimage" );
		$string .= $str . "<input type=\"button\"  class=\"button\" value=\"" . L ( 'multiple_file_list' ) . "\" onclick=\"javascript:flashupload('{$field}_multifile', '" . L ( 'attachment_upload' ) . "','{$field}',change_multifile,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/>    <input type=\"button\" class=\"button\" value=\"" . L ( 'add_remote_url' ) . "\" onclick=\"add_multifile('{$field}')\">";
		return $string;
	}
	public function editor($field, $value, $fieldinfo) {
		$grouplist = S ( 'member/grouplist' );
		$_groupid = cookie ( '_groupid' );
		$grouplist = $grouplist [$_groupid];
		extract ( $fieldinfo );
		extract ( string2array ( $setting ) );
		$disabled_page = isset ( $disabled_page ) ? $disabled_page : 0;
		if (! $height) $height = 300;
		$allowupload = defined ( 'IN_ADMIN' ) ? 1 : $grouplist ['allowattachment'] ? 1 : 0;
		if (! $value) $value = $defaultvalue;
		if ($minlength || $pattern) $allow_empty = '';
		if ($minlength) $this->formValidator .= '$("#' . $field . '").formValidator({' . $allow_empty . 'onshow:"",onfocus:"' . $errortips . '"}).functionValidator({
	fun:function(val,elem){
	if($(\'#islink\').attr(\'checked\')){
	return true;
} else if(($(\'#islink\').attr(\'checked\')==false) && (!UE.getEditor(\''.$field.'\').hasContents())){
return "' . $errortips . '";
} else if(!UE.getEditor(\''.$field.'\').hasContents()){
return "' . $errortips . '";
}
return true;
}});';
		return "<div id='{$field}_tip'></div>" . '<textarea name="info[' . $field . ']" id="' . $field . '" boxid="' . $field . '">' . $value . '</textarea><BR>' . Form::editor ( $field, $toolbar, 'content', $this->catid, '', $allowupload, 1, '', $height, $disabled_page );
	}
	public function groupid($field, $value, $fieldinfo) {
		extract ( string2array ( $fieldinfo ['setting'] ) );
		$grouplist = S ( 'member/grouplist' );
		foreach ( $grouplist as $_key => $_value ) {
			$data [$_key] = $_value ['name'];
		}
		return '<input type="hidden" name="info[' . $field . ']" value="1">' . Form::checkbox ( $data, $value, 'name="' . $field . '[]" id="' . $field . '"', '', '120' );
	}
	public function image($field, $value, $fieldinfo) {
		$setting = string2array ( $fieldinfo ['setting'] );
		extract ( $setting );
		if (! defined ( 'IMAGES_INIT' )) {
			$str = '<script type="text/javascript" src="' . JS_PATH . 'swfupload/swf2ckeditor.js"></script>';
			define ( 'IMAGES_INIT', 1 );
		}
		$html = '';
		if (defined ( 'IN_ADMIN' )) {
			$html = "<input type=\"button\" style=\"width: 66px;\" class=\"button\" onclick=\"crop_cut_" . $field . "($('#$field').val());return false;\" value=\"" . L ( 'cut_the_picture', '', 'content' ) . "\"><input type=\"button\" style=\"width: 66px;\" class=\"button\" onclick=\"$('#" . $field . "_preview').attr('src','" . IMG_PATH . "icon/upload-pic.png');$('#" . $field . "').val(' ');return false;\" value=\"" . L ( 'cancel_the_picture', '', 'content' ) . "\"><script type=\"text/javascript\">function crop_cut_" . $field . "(id){
		if (id=='') { alert('" . L ( 'upload_thumbnails', '', 'content' ) . "');return false;}
		window.top.art.dialog.open('index.php?app=content&controller=content&action=public_crop&application=content&catid='+catid+'&picurl='+encodeURIComponent(id)+'&input=$field&preview=" . ($show_type && defined ( 'IN_ADMIN' ) ? $field . "_preview" : '') . "',{title:'" . L ( 'cut_the_picture', '', 'content' ) . "',id:'crop',width:'680px',height:'480px',ok: function(iframeWin, topWin){iframeWin.uploadfile();return false;},cancel: function(){}});
	};</script>";
		}
		$authkey = upload_key ( "1,$upload_allowext,$isselectimage,$images_width,$images_height,$watermark" );
		if ($show_type && defined ( 'IN_ADMIN' )) {
			$preview_img = $value ? $value : IMG_PATH . 'icon/upload-pic.png';
			return $str . "<div class='upload-pic img-wrap'><input type='hidden' name='info[$field]' id='$field' value='$value'>
		<a href='javascript:void(0);' onclick=\"flashupload('{$field}_images', '" . L ( 'attachment_upload', '', 'content' ) . "','{$field}',thumb_images,'1,{$upload_allowext},$isselectimage,$images_width,$images_height,$watermark','content','$this->catid','$authkey');return false;\">
		<img src='$preview_img' id='{$field}_preview' width='135' height='113' style='cursor:hand' /></a>" . $html . "</div>";
		} else {
			return $str . "<input type='text' name='info[$field]' id='$field' value='$value' size='$size' class='input-text' />  <input type='button' class='button' onclick=\"flashupload('{$field}_images', '" . L ( 'attachment_upload', '', 'content' ) . "','{$field}',submit_images,'1,{$upload_allowext},$isselectimage,$images_width,$images_height,$watermark','content','$this->catid','$authkey')\"/ value='" . L ( 'upload_pic', '', 'content' ) . "'>" . $html;
		}
	}
	public function images($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$list_str = '';
		if ($value) {
			$value = string2array ( html_entity_decode ( $value, ENT_QUOTES ) );
			if (is_array ( $value )) {
				foreach ( $value as $_k => $_v ) {
					$list_str .= "<li id='image_{$field}_{$_k}' style='padding:1px'><input type='text' name='{$field}_url[]' value='{$_v[url]}' style='width:310px;' ondblclick='image_priview(this.value);' class='input-text'> <input type='text' name='{$field}_alt[]' value='{$_v[alt]}' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('image_{$field}_{$_k}')\">" . L ( 'remove_out', '', 'content' ) . "</a></li>";
				}
			}
		} else {
			$list_str .= "<center><div class='onShow' id='nameTip'>" . L ( 'upload_pic_max', '', 'content' ) . " <font color='red'>{$upload_number}</font> " . L ( 'tips_pics', '', 'content' ) . "</div></center>";
		}
		$string = '<input name="info[' . $field . ']" type="hidden" value="1">
		<fieldset class="blue pad-10">
        <legend>' . L ( 'pic_list' ) . '</legend>';
		$string .= $list_str;
		$string .= '<ul id="' . $field . '" class="picList"></ul>
		</fieldset>
		<div class="bk10"></div>
		';
		if (! defined ( 'IMAGES_INIT' )) {
			$str = '<script type="text/javascript" src="statics/js/swfupload/swf2ckeditor.js"></script>';
			define ( 'IMAGES_INIT', 1 );
		}
		$authkey = upload_key ( "$upload_number,$upload_allowext,$isselectimage" );
		$string .= $str . "<div class='picBut cu'><a herf='javascript:void(0);' onclick=\"javascript:flashupload('{$field}_images', '" . L ( 'attachment_upload' ) . "','{$field}',change_images,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/> " . L ( 'select_pic' ) . " </a></div>";
		return $string;
	}
	public function islink($field, $value, $fieldinfo) {
		if ($value) {
			$url = $this->data ['url'];
			$checked = 'checked';
			$_GET ['islink'] = 1;
		} else {
			$disabled = 'disabled';
			$url = $checked = '';
			$_GET ['islink'] = 0;
		}
		$size = $fieldinfo ['size'] ? $fieldinfo ['size'] : 25;
		return '<input type="hidden" name="info[islink]" value="0"><input type="text" name="linkurl" id="linkurl" value="' . $url . '" size="' . $size . '" maxlength="255" ' . $disabled . ' class="input-text"> <input name="info[islink]" type="checkbox" id="islink" value="1" onclick="ruselinkurl();" ' . $checked . '> <font color="red">' . L ( 'islink_url' ) . '</font>';
	}
	public function keyword($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		if (! $value) $value = $defaultvalue;
		return "<input type='text' name='info[$field]' id='$field' value='$value' style='width:280px' {$formattribute} {$css} class='input-text'>";
	}
	function linkage($field, $value, $fieldinfo) {
		$setting = string2array ( $fieldinfo ['setting'] );
		$linkageid = $setting ['linkageid'];
		return menu_linkage ( $linkageid, $field, $value );
	}
	function map($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		$size = $setting ['size'];
		$errortips = $this->fields [$field] ['errortips'];
		$modelid = $this->fields [$field] ['modelid'];
		$tips = $value ? L ( 'editmark', '', 'map' ) : L ( 'addmark', '', 'map' );
		return '<input type="text" name="info[' . $field . ']" value="' . $value . '" id="' . $field . '" ><input type="button" name="' . $field . '_mark" id="' . $field . '_mark" value="' . $tips . '" class="btn btn-primary btn-sm"onclick="omnipotent(\'selectid\',\'' . SITE_URL . 'api.php?c=map&&a=init&field=' . $field . '&modelid=' . $modelid . '\',\'' . L ( 'mapmark', '', 'map' ) . '\',1,700,420)">';
	}
	public function number($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		$size = $setting ['size'];
		if (! $value) $value = $defaultvalue;
		return "<input type='text' name='info[$field]' id='$field' value='$value' class='input-text' size='$size' {$formattribute} {$css}>";
	}
	public function omnipotent($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		if (! $value) $value = $setting ['defaultvalue'];
		$formtext = str_replace ( '{FIELD_VALUE}', $value, $formtext );
		$formtext = str_replace ( '{MODELID}', $this->modelid, $formtext );
		preg_match_all ( '/{FUNC\((.*)\)}/', $formtext, $_match );
		foreach ( $_match [1] as $key => $match_func ) {
			$string = '';
			$params = explode ( '~~', $match_func );
			$user_func = $params [0];
			$string = $user_func ( $params [1] );
			$formtext = str_replace ( $_match [0] [$key], $string, $formtext );
		}
		$id = $this->id ? $this->id : 0;
		$formtext = str_replace ( '{ID}', $id, $formtext );
		$errortips = $this->fields [$field] ['errortips'];
		if ($errortips) $this->formValidator .= '$("#' . $field . '").formValidator({onshow:"",onfocus:"' . $errortips . '"}).inputValidator({min:' . $minlength . ',max:' . $maxlength . ',onerror:"' . $errortips . '"});';

		if ($errortips) $this->formValidator .= '$("#' . $field . '").formValidator({onshow:"' . $errortips . '",onfocus:"' . $errortips . '"}).inputValidator({min:1,onerror:"' . $errortips . '"});';
		return $formtext;
	}
	public function pages($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		if ($value) {
			$v = explode ( '|', $value );
			$data = "<select name=\"info[paginationtype]\" id=\"paginationtype\" onchange=\"if(this.value==1)\$('#paginationtype1').css('display','');else \$('#paginationtype1').css('display','none');\">";
			$type = array (L ( 'page_type1' ),L ( 'page_type2' ),L ( 'page_type3' ) );
			if ($v [0] == 1)
				$con = 'style="display:"';
			else
				$con = 'style="display:none"';
			foreach ( $type as $i => $val ) {
				if ($i == $v [0])
					$tag = 'selected';
				else
					$tag = '';
				$data .= "<option value=\"$i\" $tag>$val</option>";
			}
			$data .= "</select><span id=\"paginationtype1\" $con><input name=\"info[maxcharperpage]\" type=\"text\" id=\"maxcharperpage\" value=\"$v[1]\" size=\"8\" maxlength=\"8\">" . L ( 'page_maxlength' ) . "</span>";
			return $data;
		} else {
			return "<select name=\"info[paginationtype]\" id=\"paginationtype\" onchange=\"if(this.value==1)\$('#paginationtype1').css('display','');else \$('#paginationtype1').css('display','none');\">
                <option value=\"0\">" . L ( 'page_type1' ) . "</option>
                <option value=\"1\">" . L ( 'page_type2' ) . "</option>
                <option value=\"2\">" . L ( 'page_type3' ) . "</option>
            </select>
			<span id=\"paginationtype1\" style=\"display:none\"><input name=\"info[maxcharperpage]\" type=\"text\" id=\"maxcharperpage\" value=\"5000\" size=\"8\" maxlength=\"8\">" . L ( 'page_maxlength' ) . "</span>";
		}
	}
	public function posid($field, $value, $fieldinfo) {
		$setting = string2array ( $fieldinfo ['setting'] );
		$position = S ( 'common/position' );
		if (empty ( $position )) return '';
		$array = array ();
		foreach ( $position as $_key => $_value ) {
			if ($_value ['modelid'] && ($_value ['modelid'] != $this->modelid) || ($_value ['catid'] && strpos ( ',' . $this->categorys [$_value ['catid']] ['arrchildid'] . ',', ',' . $this->catid . ',' ) === false)) continue;
			$array [$_key] = $_value ['name'];
		}
		$posids = array ();
		if (ACTION == 'edit') {
			$this->position_data_db = Loader::model ( 'position_data_model' );
			$result = $this->position_data_db->where ( array ('id' => $this->id,'modelid' => $this->modelid ) )->key ( 'posid' )->select ();
			$posids = implode ( ',', array_keys ( $result ) );
		} else {
			$posids = $setting ['defaultvalue'];
		}
		return "<input type='hidden' name='info[$field][]' value='-1'>" . Form::checkbox ( $array, $posids, "name='info[$field][]'", '', $setting ['width'] );
	}
	public function readpoint($field, $value = '0', $fieldinfo) {
		if (empty ( $value )) $value = 0;
		$paytype = $this->data ['paytype'];
		if ($paytype) {
			$checked1 = '';
			$checked2 = 'checked';
		} else {
			$checked1 = 'checked';
			$checked2 = '';
		}
		return '<input type="text" name="info[' . $field . ']" value="' . $value . '" size="5"><input type="radio" name="info[paytype]" value="0" ' . $checked1 . '> ' . L ( 'point' ) . ' <input type="radio" name="info[paytype]" value="1" ' . $checked2 . '>' . L ( 'money' );
	}
	public function template($field, $value, $fieldinfo) {
		$default_style = C ( 'template', 'name' );
		return Form::select_template ( $default_style, 'content', $value, 'name="info[' . $field . ']" id="' . $field . '"', 'show' );
	}
	public function text($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		$size = $setting ['size'];
		if (! $value) $value = $defaultvalue;
		$type = $ispassword ? 'password' : 'text';
		$errortips = $this->fields [$field] ['errortips'];
		if ($errortips || $minlength) $this->formValidator .= '$("#' . $field . '").formValidator({onshow:"",onfocus:"' . $errortips . '"}).inputValidator({min:1,onerror:"' . $errortips . '"});';
		return '<input type="text" name="info[' . $field . ']" id="' . $field . '" size="' . $size . '" value="' . $value . '" class="input-text" ' . $formattribute . ' ' . $css . '>';
	}
	public function textarea($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		extract ( $setting );
		if (! $value) $value = $defaultvalue;
		$allow_empty = 'empty:true,';
		if ($minlength || $pattern) $allow_empty = '';
		if ($errortips) $this->formValidator .= '$("#' . $field . '").formValidator({' . $allow_empty . 'onshow:"' . $errortips . '",onfocus:"' . $errortips . '"}).inputValidator({min:1,onerror:"' . $errortips . '"});';
		$value = empty ( $value ) ? $setting [defaultvalue] : $value;
		$str = "<textarea name='info[{$field}]' id='$field' style='width:{$width}%;height:{$height}px;' $formattribute $css";
		if ($maxlength) $str .= " onkeyup=\"strlen_verify(this, '{$field}_len', {$maxlength})\"";
		$str .= ">{$value}</textarea>";
		if ($maxlength) $str .= L ( 'can_enter' ) . '<B><span id="' . $field . '_len">' . $maxlength . '</span></B> ' . L ( 'characters' );
		return $str;
	}
	public function title($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$style_arr = explode ( ';', $this->data ['style'] );
		$style_color = $style_arr [0];
		$style_font_weight = $style_arr [1] ? $style_arr [1] : '';
		$style = 'color:' . $this->data ['style'];
		if (! $value) $value = $defaultvalue;
		$errortips = $this->fields [$field] ['errortips'];
		$errortips_max = L ( 'title_is_empty' );
		if ($errortips) $this->formValidator .= '$("#' . $field . '").formValidator({onshow:"",onfocus:"' . $errortips . '"}).inputValidator({min:' . $minlength . ',max:' . $maxlength . ',onerror:"' . $errortips_max . '"});';
		$str = '<input type="text" style="width:400px;' . ($style_color ? 'color:' . $style_color . ';' : '') . ($style_font_weight ? 'font-weight:' . $style_font_weight . ';' : '') . '" name="info[' . $field . ']" id="' . $field . '" value="' . $value . '" style="' . $style . '" class="measure-input " onBlur="$.post(\'api.php?controller=keyword&action=get&number=3&sid=\'+Math.random()*5, {data:$(\'#title\').val()}, function(data){if(data && $(\'#keywords\').val()==\'\') $(\'#keywords\').val(data); })" onkeyup="strlen_verify(this, \'title_len\', ' . $maxlength . ');"/><input type="hidden" name="style_color" id="style_color" value="' . $style_color . '">
		<input type="hidden" name="style_font_weight" id="style_font_weight" value="' . $style_font_weight . '">';
		if (defined ( 'IN_ADMIN' )) $str .= '<input type="button" class="btn btn-primary btn-sm"id="check_title_alt" value="' . L ( 'check_title', '', 'content' ) . '" onclick="$.get(\'?app=content&controller=content&action=public_check_title&catid=' . $this->catid . '&sid=\'+Math.random()*5, {data:$(\'#title\').val()}, function(data){if(data==\'1\') {$(\'#check_title_alt\').val(\'' . L ( 'title_repeat' ) . '\');$(\'#check_title_alt\').css(\'background-color\',\'#FFCC66\');} else if(data==\'0\') {$(\'#check_title_alt\').val(\'' . L ( 'title_not_repeat' ) . '\');$(\'#check_title_alt\').css(\'background-color\',\'#F8FFE1\')}})" style="width:73px;"/><img src="' . IMG_PATH . 'icon/colour.png" width="15" height="16" onclick="colorpicker(\'' . $field . '_colorpanel\',\'set_title_color\');" style="cursor:hand"/>
		<img src="' . IMG_PATH . 'icon/bold.png" width="10" height="10" onclick="input_font_bold()" style="cursor:hand"/> <span id="' . $field . '_colorpanel" style="position:absolute;" class="colorpanel"></span>';
		$str .= L ( 'can_enter' ) . '<B><span id="title_len">' . $maxlength . '</span></B> ' . L ( 'characters' );
		return $str;
	}
	public function typeid($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$setting = string2array ( $setting );
		if (! $value) $value = $setting ['defaultvalue'];
		if ($errortips) {
			$errortips = $this->fields [$field] ['errortips'];
			$this->formValidator .= '$("#' . $field . '").formValidator({onshow:"",onfocus:"' . $errortips . '"}).inputValidator({min:1,onerror:"' . $errortips . '"});';
		}
		$usable_type = $this->categorys [$this->catid] ['usable_type'];
		$usable_array = array ();
		if ($usable_type) $usable_array = explode ( ',', $usable_type );

		$type_data = S ( 'common/type_content' );
		foreach ( $type_data as $_key => $_value ) {
			if (in_array ( $_key, $usable_array )) $data [$_key] = $_value ['name'];
		}
		return Form::select ( $data, $value, 'name="info[' . $field . ']" id="' . $field . '" ' . $formattribute . ' ' . $css, L ( 'copyfrom_tips' ) );
	}
	public function video($field, $value, $fieldinfo) {
		extract ( $fieldinfo );
		$textheight = $textheight ? $textheight : 100;
		$list_str = '';
		if ($value && ! empty ( $value )) {
			$value = string2array ( html_entity_decode ( $value, ENT_QUOTES ) );
			if (is_array ( $value )) {
				foreach ( $value as $_k => $_v ) {
					$list_str .= "<li id='image{$_k}' style='padding:1px'><input type='text' name='{$field}_url[]' value='{$_v[url]}' style='width:310px;' ondblclick='image_priview(this.value);' class='input-text'> <input type='text' name='{$field}_alt[]' value='{$_v[alt]}' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('image{$_k}')\">" . L ( 'remove_out', '', 'content' ) . "</a></li>";
				}
			}
		} else {
			$list_str .= "<center><div class='onShow' id='nameTip'>" . L ( 'upload_pic_max', '', 'content' ) . " <font color='red'>{$upload_number}</font> " . L ( 'tips_pics', '', 'content' ) . "</div></center>";
		}
		$list_str .= "<textarea style='width:98%;height:" . $textheight . "px;' name='" . $field . "'></textarea>";
		$string = '<input name="info[' . $field . ']" type="hidden" value="1">
		<fieldset class="blue pad-10">
		<legend>' . $field . '列表</legend>';
		$string .= $list_str;
		$string .= '<ul id="' . $field . '" class="picList"></ul>
		</fieldset>
		<div class="bk10"></div>
		';
		if (! defined ( 'IMAGES_INIT' )) {
			$str = '<script type="text/javascript" src="statics/js/swfupload/swf2ckeditor.js"></script>';
			define ( 'IMAGES_INIT', 1 );
		}
		$authkey = upload_key ( "$upload_number,$upload_allowext,$isselectimage" );
		$string .= $str . "<div class='picBut cu'><a herf='javascript:void(0);' onclick=\"javascript:flashupload('{$field}_images', '" . L ( 'attachment_upload' ) . "','{$field}',change_images,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/> 选择" . $field . " </a></div>";
		// add player
		$playerlists = array ('0' => '请选择默认播放器' );
		$playerlist = S ( 'common/player' );
		foreach ( ( array ) $playerlist as $k => $v ) {
			$playerlists [$v ['playerid']] = $v ['subject'];
		}
		$string .= Form::select ( $playerlists, $_v ['p'] ? $_v ['p'] : $defaultplayer, 'name="' . $field . '_defaultplayer"' );
		return $string;
	}
}?>